from django.db import models
from django.utils import timezone

# 相机分类模型
class CameraCategory(models.Model):
    name = models.CharField(max_length=100, verbose_name='分类名称')
    description = models.TextField(blank=True, null=True, verbose_name='分类描述')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    
    def __str__(self):
        return self.name
    
    class Meta:
        verbose_name = '相机分类'
        verbose_name_plural = '相机分类'

# 相机词条模型
class CameraEntry(models.Model):
    title = models.CharField(max_length=200, verbose_name='相机名称')
    content = models.TextField(verbose_name='相机详情')
    category = models.ForeignKey(CameraCategory, on_delete=models.CASCADE, related_name='cameras', verbose_name='所属分类')
    brand = models.CharField(max_length=100, verbose_name='品牌')
    release_date = models.DateField(blank=True, null=True, verbose_name='发布日期')
    sensor_type = models.CharField(max_length=100, blank=True, null=True, verbose_name='传感器类型')
    image_resolution = models.CharField(max_length=100, blank=True, null=True, verbose_name='图像分辨率')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    def __str__(self):
        return self.title
    
    class Meta:
        verbose_name = '相机词条'
        verbose_name_plural = '相机词条'

# 配件分类模型
class AccessoryCategory(models.Model):
    name = models.CharField(max_length=100, verbose_name='配件分类名称')
    description = models.TextField(blank=True, null=True, verbose_name='分类描述')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    
    def __str__(self):
        return self.name
    
    class Meta:
        verbose_name = '配件分类'
        verbose_name_plural = '配件分类'

# 相机配件模型
class CameraAccessory(models.Model):
    title = models.CharField(max_length=200, verbose_name='配件名称')
    content = models.TextField(verbose_name='配件详情')
    category = models.ForeignKey(AccessoryCategory, on_delete=models.CASCADE, related_name='accessories', verbose_name='所属分类')
    brand = models.CharField(max_length=100, verbose_name='品牌')
    compatible_cameras = models.ManyToManyField(CameraEntry, blank=True, related_name='compatible_accessories', verbose_name='兼容相机')
    price_range = models.CharField(max_length=100, blank=True, null=True, verbose_name='价格范围')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    def __str__(self):
        return self.title
    
    class Meta:
        verbose_name = '相机配件'
        verbose_name_plural = '相机配件'
